#include "pch.h"
#include "include/define.h"

// #include <ws2def.h>
// #include <WinSock2.h>

static char buff[64]={0};
//-------------------------------------------------------------------------------------
const char* str(UINT64 qwValue, char* buf, UINT32 bufsize)
{
	return buff;
}
const char* strDec(UINT64 qwValue, char* buf, UINT32 bufsize)
{
	return buff;
}

// not thread safe
const char* str(UINT64 qwValue)
{
	return buff;
}
const char* strHex(UINT64 qwValue)
{
	return buff;
}
const char* strDec(UINT64 qwValue)
{
	return buff;
}

int IPAddress::string2ip(const char* string, UINT32& address)
{
	UINT32	trial;

#ifdef unix
	if (inet_aton(string, (struct in_addr*)&trial) != 0)
#else
	if ((trial = inet_addr(string)) != INADDR_NONE)
#endif
	{
		address = trial;
		return 0;
	}

	struct hostent* hosts = gethostbyname(string);
	if (hosts != NULL)
	{
		address = *(UINT32*)(hosts->h_addr_list[0]);
		return 0;
	}

	return -1;
}

//-------------------------------------------------------------------------------------
int IPAddress::ip2string(UINT32 address, char* string)
{
	address = ntohl(address);

	int p1, p2, p3, p4;
	p1 = address >> 24;
	p2 = (address & 0xffffff) >> 16;
	p3 = (address & 0xffff) >> 8;
	p4 = (address & 0xff);

	return sprintf(string, "%d.%d.%d.%d", p1, p2, p3, p4);
}
